package com.cci.kangdao.controller;

import com.cci.kangdao.service.MailBoxService;
import com.cci.kangdao.utilTool.ParameterTool;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author William Du
 * @date 2019/10/11
 */
@Controller
public class MailBoxController {

    private Logger log = Logger.getLogger(this.getClass().getName());

    @Resource
    private MailBoxService mailBoxService;

    /**
     * 获取站内信列表
     * @param request request
     * @param response response
     * @return null
     */
    @RequestMapping("/getMessageList.aspx")
    public String getMessageList(HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
            map.put("response", response);
            mailBoxService.getMessageList(map);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            ParameterTool.writeErrorResponse(response);
        }
        return null;
    }

    /**
     * 发送站内信接口
     * @param request request
     * @param response response
     * @return null
     */
    @RequestMapping("/pushMessage.aspx")
    public String pushMessage(HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
            map.put("response", response);
            mailBoxService.pushMessage(map);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            ParameterTool.writeErrorResponse(response);
        }
        return null;
    }

}
